package net.wenku8.reader.view.file

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import net.wenku8.reader.LocalNavController
import net.wenku8.reader.R
import net.wenku8.reader.entity.BookFile
import net.wenku8.reader.enums.RouteFileDetail
import net.wenku8.reader.state.StateReadFile
import net.wenku8.reader.ui.lite.LiteCard
import net.wenku8.reader.ui.lite.LiteText
import net.wenku8.reader.ui.lite.LiteTitle
import net.wenku8.reader.ui.lite.cardImage
import net.wenku8.reader.ui.theme.LiteRed

@Composable
fun FileBookPreview(bookFile : BookFile, onClick : Boolean = true) {
    val navController = LocalNavController.current
    LiteCard(
        left = {
            Image(
                painter = painterResource(id = R.mipmap.book_file_cover),
                contentDescription = null,
                modifier = Modifier.cardImage()
            )
        },
        header = {
            LiteTitle(text = bookFile.title?:"", color = LiteRed)
        },
        onClick = {
            if (onClick){
                StateReadFile.bookFile.value = bookFile
                navController.navigate(RouteFileDetail)
            }
        }
    ){
        Column{
            if (bookFile.chapterSize > 0){
                LiteText(text = "总字数：" + (bookFile.textSize/10000 + 1) + "万" )
                LiteText(text = "总章节：" + bookFile.chapterSize)
            } else {
                LiteText(text = "总字数：未读取")
                LiteText(text = "总章节：未读取")
            }
        }
    }

}